package com.yeu.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.yeu.model.Menu;
import com.yeu.util.ConnectionPool;

public class MenuAction extends ActionSupport implements SessionAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String roleId;
	private String name;
	private List<Map<String, String>> result;

	public List<Map<String, String>> getResult() {
		return result;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		roleId=(String) session.get("roleId");
		name=(String) session.get("userName");
	}
	
	@Override
	public String execute() throws Exception {
		getMenuFromDB();
		return SUCCESS;
	}
	
	public String name() throws Exception {
		Map<String, String> resultMap=new HashMap<String, String>();
		resultMap.put("USERNAME", name);
		result=new ArrayList<Map<String,String>>();
		result.add(resultMap);
		return SUCCESS;
	}
	
	private void getMenuFromDB(){
		String sql="select * from MENUITEM where ROLEID=?";
		result=ConnectionPool.executeQuery(sql,roleId);
	}
}
